package com.java110.mall.goods.smo.impl;


import com.java110.intf.goods.IDistributionModeInnerServiceSMO;
import com.java110.dto.distributionMode.DistributionModeDto;
import com.java110.mall.goods.dao.IDistributionModeServiceDao;
import com.java110.po.distributionMode.DistributionModePo;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.user.UserDto;
import com.java110.dto.PageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 派送方式内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class DistributionModeInnerServiceSMOImpl extends BaseServiceSMO implements IDistributionModeInnerServiceSMO {

    @Autowired
    private IDistributionModeServiceDao distributionModeServiceDaoImpl;


    @Override
    public int saveDistributionMode(@RequestBody  DistributionModePo distributionModePo) {
        int saveFlag = 1;
        distributionModeServiceDaoImpl.saveDistributionModeInfo(BeanConvertUtil.beanCovertMap(distributionModePo));
        return saveFlag;
    }

     @Override
    public int updateDistributionMode(@RequestBody  DistributionModePo distributionModePo) {
        int saveFlag = 1;
         distributionModeServiceDaoImpl.updateDistributionModeInfo(BeanConvertUtil.beanCovertMap(distributionModePo));
        return saveFlag;
    }

     @Override
    public int deleteDistributionMode(@RequestBody  DistributionModePo distributionModePo) {
        int saveFlag = 1;
        distributionModePo.setStatusCd("1");
        distributionModeServiceDaoImpl.updateDistributionModeInfo(BeanConvertUtil.beanCovertMap(distributionModePo));
        return saveFlag;
    }

    @Override
    public List<DistributionModeDto> queryDistributionModes(@RequestBody  DistributionModeDto distributionModeDto) {

        //校验是否传了 分页信息

        int page = distributionModeDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            distributionModeDto.setPage((page - 1) * distributionModeDto.getRow());
        }

        List<DistributionModeDto> distributionModes = BeanConvertUtil.covertBeanList(distributionModeServiceDaoImpl.getDistributionModeInfo(BeanConvertUtil.beanCovertMap(distributionModeDto)), DistributionModeDto.class);

        return distributionModes;
    }


    @Override
    public int queryDistributionModesCount(@RequestBody DistributionModeDto distributionModeDto) {
        return distributionModeServiceDaoImpl.queryDistributionModesCount(BeanConvertUtil.beanCovertMap(distributionModeDto));    }

    public IDistributionModeServiceDao getDistributionModeServiceDaoImpl() {
        return distributionModeServiceDaoImpl;
    }

    public void setDistributionModeServiceDaoImpl(IDistributionModeServiceDao distributionModeServiceDaoImpl) {
        this.distributionModeServiceDaoImpl = distributionModeServiceDaoImpl;
    }
}
